package com.hiultra.common.utils;

import org.apache.commons.lang3.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


public class OrderNoUtil {

    private static final String ORDER_BORROW_PREFIX = "JY";

    private static Map<String, Integer> counter = new HashMap();
    private static int orderNum = 1;

    // 生成一个借阅单编号
    public static String createBorrowNo() {
        return createNo(ORDER_BORROW_PREFIX);
    }

    // 生成一个id
    public static synchronized String createNo(String prefix) {
        String str = new SimpleDateFormat("yyyyMMdd").format(new Date());
        Integer no = counter.get(prefix);
        if (no == null) {
            no = 0;
            counter.put(prefix, no);
        }
        no++;
        String strNo = StringUtils.leftPad(no.toString(), 5, "0");
        return prefix + str + strNo;
    }
}
